package com.beordie.controller;

import com.beordie.model.Seller;
import com.beordie.model.User;
import com.beordie.service.ISellerService;
import com.beordie.service.IUserService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @Description 用户管理控制层
 * @Date 2021/8/4 20:00
 * @Created 30500
 */
@RequestMapping("seller")
@Controller
public class SellerController {
    @Resource
    private ISellerService sellerServiceImpl;

    @RequestMapping(value = "list")
    public String pageInfo(@RequestParam(defaultValue = "1") int pageNum,
                           @RequestParam(defaultValue = "5") int pageSize,
                           Seller seller, Model model) {

        PageInfo<Seller> pageInfo = sellerServiceImpl.findPage(seller, pageNum, pageSize);
        model.addAttribute("page", pageInfo);
        return "/seller/list";
    }

    @RequestMapping(value = "toUpdate/{id}", method = RequestMethod.GET)
    public String tpUpdate(@PathVariable("id") int id, Model model) {
        Seller seller = sellerServiceImpl.findById(id);
        model.addAttribute("seller", seller);
        return "/seller/update";
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public String update(int id, Seller seller) {
        seller.setId(id);
        int update = sellerServiceImpl.update(seller);
        return "redirect:/seller/list";
    }

    @RequestMapping("toAdd")
    public String toAdd() {
        return "/seller/add";
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public String add(Seller seller) {
        int add = sellerServiceImpl.add(seller);
        return "redirect:/seller/list";
    }

    @RequestMapping(value = "delete/{id}", method = RequestMethod.GET)
    public String delete(@PathVariable("id") int id) {
        int delete = sellerServiceImpl.delete(id);
        return "redirect:/seller/list";
    }

}
